package com.tn.logfitercontroller;

import com.gitee.hifong45.FE;
import com.gitee.hifong45.Ret;
import com.tn.controller.alarm.common.model.CommonVO;
import com.tn.controller.alarm.common.model.PageInput;
import com.tn.controller.alarm.common.model.PageResult;
import com.tn.controller.alarm.common.model.gate.vo.GateLogInfoVO;
import com.tn.controller.alarm.common.model.gate.vo.GateLogQueryVO;
import com.tn.controller.alarm.common.model.weigh.vo.WeighLogInfoVO;
import com.tn.controller.alarm.common.model.weigh.vo.WeighLogQueryVO;
import com.tn.dao.key.ShortcutKey;
import com.tn.dao.mbpdao.TaskInfo;
import com.tn.exception.InvalidParamException;
import com.tn.service.gate.IGateService;
import com.tn.service.key.ShortcutKeyService;
import com.tn.service.vehicle.impl.VehicleServiceImpl;
import com.tn.service.weigh.IWeighService;
import com.tn.service.weigh.impl.WeighServiceImpl;
import com.tn.utils.CheckParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 闸口controller
 *
 * @program: tn_aucy_java
 * @author: yangjiayao
 * @create: 2021/11/16
 */
@Slf4j
@RestController
@RequestMapping("/aucy")
public class LogFilterController {

    @Resource
    private IGateService gateService;

    @Resource
    private WeighServiceImpl weighServiceImpl;

    @Resource
    private IWeighService weighService;

    @Resource
    private VehicleServiceImpl vehicleServiceImpl;

    @Autowired
    private ShortcutKeyService shortcutKeyService;


    /**
     * 查询闸口日志信息
     *
     * @param queryVO 查询条件
     * @return 闸口日志信息
     * @throws InvalidParamException 异常
     */
    @RequestMapping("/gateLogInfo")
    public CommonVO<PageResult<GateLogInfoVO>> gateLogInfo(@RequestBody PageInput<GateLogQueryVO> queryVO)
            throws InvalidParamException {
        CheckParamUtil.checkPageParam(queryVO.getCurPage(), queryVO.getPageSize());
        CheckParamUtil.checkNullRequiredParam(queryVO.getData());
        return gateService.getGateLogInfo(queryVO.getCurPage(), queryVO.getPageSize(), queryVO.getData());
    }

    /**
     * 查询货车是否取卡
     * @param license
     * @return
     */
    @GetMapping("/selectTruckTagStatus")
    public Ret<Object> selectTruckTagStatus(String license) {
        FE.nullThrow(license, "license");

        Integer ret = weighServiceImpl.selectTruckTagStatus(license);
        return Ret.Ok(ret);
    }



    /**
     * 查询磅房日志信息
     *
     * @param queryVO 查询条件
     * @return 磅房日志信息
     * @throws InvalidParamException 异常
     */
    @RequestMapping("/weighLogInfo")
    public CommonVO<PageResult<WeighLogInfoVO>> weighLogInfo(@RequestBody PageInput<WeighLogQueryVO> queryVO)
            throws InvalidParamException {
        CheckParamUtil.checkPageParam(queryVO.getCurPage(), queryVO.getPageSize());
        CheckParamUtil.checkNullRequiredParam(queryVO.getData());
        return weighService.getWeighLogInfo(queryVO.getCurPage(), queryVO.getPageSize(), queryVO.getData());
    }

    /**
     * 查询总任务，或某装载车已接任务。
     * @return
     */
    @GetMapping("/vehicle/task")
    public Ret<Map<String, List<TaskInfo>>> getTallyTask(String license, Integer days) {
        FE.nullThrow(license, "license");
        if(days == null) {
            days = 2;
        }
        Map<String, List<TaskInfo>> ret = vehicleServiceImpl.getAllTask(license, days);
        return Ret.Ok(ret);
    }


    @PostMapping("/selectWeighLogLicense")
    public Ret<Object> selectWeighLogLicense(){
        return Ret.Ok( weighServiceImpl.selectWeighLogLicense());
    }


    /**
     * 查询快捷键列表
     */
    @RequestMapping(value = "/key/list", method = {RequestMethod.POST}, produces = "application/json")
    public CommonVO<Object> list(@RequestBody ShortcutKey shortcutKey)
    {
        List<ShortcutKey> info = shortcutKeyService.selectShortcutKeyList(shortcutKey);
        return new CommonVO<>(info);
    }


    /**
     * 查询称重汇总的条件
     * @return
     */
    @GetMapping("/queryWeightSumConditionList")
    public CommonVO<Map<String,List<String>>> queryWeightSumCondition()  {
        return  weighServiceImpl.queryWeightSumCondition();
    }

}
